package com.gaussian.property.admin.module.biz.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gaussian.property.admin.module.biz.service.ProjectCheckTableService;
import com.gaussian.property.admin.module.biz.vo.projectconfig.AddProjectCheckTable;
import com.gaussian.property.admin.module.biz.vo.projectconfig.EditProjectCheckTable;
import com.gaussian.property.admin.module.biz.vo.projectconfig.PageQueryProjectRequest;
import com.gaussian.property.module.biz.entity.OptRole;
import com.gaussian.property.module.biz.service.IOptRoleService;
import com.gaussian.property.module.biz.vo.projectchecktable.PageQueryProjectTableRequest;
import com.gaussian.property.module.biz.vo.projectchecktable.ProjectCheckTableDetail;
import com.songqi.common.core.domain.OptionVo;
import com.songqi.common.core.domain.R;
import com.songqi.common.core.domain.page.PageDataInfo;
import com.songqi.common.core.validationgroup.AddGroup;
import com.songqi.common.core.validationgroup.EditGroup;
import com.songqi.common.web.request.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.groups.Default;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: songqi(13776346982)
 * @date: 2024/4/16 11:28
 */
@Api(tags = "项目绑定的稽核表")
@Validated
@RestController
@RequestMapping("projectCheckTableBinding/")
public class ProjectConfigController extends BaseController {

    @Resource
    private ProjectCheckTableService projectCheckTableService;
    @Resource
    private IOptRoleService iRoleService;

    @ApiOperation("分页查询项目绑定的稽核表(稽核标准)")
    @GetMapping("pageQueryProjectTable")
    public R<PageDataInfo<ProjectCheckTableDetail>> pageQueryProjectTable(PageQueryProjectTableRequest queryRequest){
        IPage<ProjectCheckTableDetail> pageData = projectCheckTableService.pageQueryProjectTable(queryRequest);
        return getReturnDataTableInfo(pageData);
    }

    @ApiOperation("分页查询项目信息")
    @GetMapping("pageQueryProject")
    public R<PageDataInfo<OptionVo>> pageQueryProject(PageQueryProjectRequest queryProjectRequest){
        return R.success(projectCheckTableService.pageQueryProject(queryProjectRequest));

    }

    @ApiOperation("查询所有角色下拉列表")
    @GetMapping("listRole")
    public R<List<OptionVo>> listRole(){
        List<OptionVo> optionVoList = new ArrayList<>();
        List<OptRole> list = iRoleService.list();
        if(CollectionUtil.isNotEmpty(list)){
            for(OptRole role : list){
                OptionVo optionVo = new OptionVo();
                optionVo.setValue(role.getOptRoleId());
                optionVo.setName(role.getName());
                optionVoList.add(optionVo);
            }
        }
        return R.success(optionVoList);
    }

    @ApiOperation("新增项目绑定的稽核表(稽核标准)")
    @PostMapping("add")
    public R<Void> add(@Validated({AddGroup.class, Default.class}) @RequestBody AddProjectCheckTable addProjectCheckTable) {
        projectCheckTableService.add(addProjectCheckTable);
        return R.ok();
    }


    @ApiOperation("编辑项目绑定的稽核表(稽核标准)")
    @PostMapping("edit")
    public R<Void> edit(@Validated({EditGroup.class, Default.class}) @RequestBody EditProjectCheckTable editProjectCheckTable) {
        projectCheckTableService.edit(editProjectCheckTable);
        return R.ok();
    }


    @ApiOperation("删除项目绑定的稽核表(稽核标准)")
    @PostMapping("/del/{projectCheckTableId}")
    public R<Void> delete(@ApiParam("项目绑定的稽核表的绑定id")@PathVariable String projectCheckTableId) {
        projectCheckTableService.delete(projectCheckTableId);
        return success();
    }



    @ApiOperation("停用/启用项目绑定的稽核表(稽核标准)。返回更新后的状态。1-启用，0-停用")
    @PostMapping("changeStatus/{projectCheckTableId}")
    public R<Integer> changeStatus(@ApiParam("项目绑定的稽核表(稽核标准)id") @PathVariable String projectCheckTableId) {
        Integer status = projectCheckTableService.changeStatus(projectCheckTableId);
        return R.ok(status);
    }

}
